package com.infodms.dms.actions.sales.marketmanage.planmanage;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.common.FileUploadManager;
import com.infodms.dms.actions.sales.marketmanage.planissued.ActivitiesCostOpera;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.sales.dealer.DealerInfoDao;
import com.infodms.dms.dao.sales.marketmanage.planmanage.ActivitiesPlanManageDao;
import com.infodms.dms.dao.sales.planmanage.SpacePlanReportDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.FsFileuploadPO;
import com.infodms.dms.po.TtCamCampaignCostPO;
import com.infodms.dms.po.TtCamMediaCostPO;
import com.infodms.dms.po.TtCampaignAttachPO;
import com.infodms.dms.po.TtCampaignExecutePO;
import com.infodms.dms.po.TtCampaignGroupRPO;
import com.infodms.dms.po.TtCampaignPO;
import com.infodms.dms.po.TtCampaignTargetPO;
import com.infodms.dms.po.TtVsCostPO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;
/**
 * @Title: 活动执行方案提报Action
 * @Description:InfoFrame3.0.V01
 * @Copyright: Copyright (c) 2010
 * @Company: www.infoservice.com.cn
 * @Date: 2010-6-30
 * @author 
 * @mail  
 * @version 1.0
 * @remark 
 */
public class ActivitiesPlanReport {
	
	public Logger logger = Logger.getLogger(ActivitiesPlanReport.class);   
	ActivitiesPlanManageDao dao  = ActivitiesPlanManageDao.getInstance();
	private ActionContext act = ActionContext.getContext();
	RequestWrapper request = act.getRequest();
	private final String initUrl = "/jsp/sales/marketmanage/planmanage/activitiesPlanReport.jsp";
	private final String addUrl = "/jsp/sales/marketmanage/planmanage/activitiesPlanReportAdd.jsp";
	private final String detailUrl = "/jsp/sales/marketmanage/planmanage/activitiesPlanReportDetail.jsp";
	/**
	 * 活动执行方案提报页面初始化
	 */
	public void activitiesPlanReportInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
			act.setOutData("areaList", areaList);
			act.setForword(initUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动方案提报页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案提报查询
	 */
	public void activitiesPlanReportQuery(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			Long poseId = logonUser.getPoseId() ;
			String campaignNo = request.getParamValue("campaignNo");			//方案编号
			String campaignName = request.getParamValue("campaignName");		//方案名称
			String campaignSubject = request.getParamValue("campaignSubject");	//活动主题
			String campaignType = request.getParamValue("campaignType");		//活动类别
			String startDate = request.getParamValue("startDate");				//开始时间
			String endDate = request.getParamValue("endDate");					//结束时间
			String areaId = request.getParamValue("areaId");					//业务范围ID
			
			String dealerId = logonUser.getDealerId().toString();
			Integer curPage = request.getParamValue("curPage") !=null ? Integer.parseInt(request.getParamValue("curPage")) : 1;
			PageResult<Map<String, Object>> ps= dao.activitiesPlanReportQuery(poseId, areaId, campaignNo, campaignName, campaignSubject, campaignType, startDate, endDate, dealerId, curPage, Constant.PAGE_SIZE);
			act.setOutData("ps", ps);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动执行方案提报查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案提报新增页面初始化
	 */
	public void activitiesPlanReportAddInit(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String areaId=request.getParamValue("area_id");
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
			List<Map<String, Object>> list = dao.selectPinPai(oemCompanyId);
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getDealerBusiness(logonUser.getPoseId().toString());
			String dealerIds=logonUser.getDealerId();
			List<Map<String, Object>> amountList1 = dao.queryDealerCost(dealerIds,areaId);
			List<Map<String, Object>> amountList2 = dao.queryAreaCost(dealerIds,areaId);
			List<Map<String, Object>> amountList3 = dao.queryOemCost();
			
			String orgId=String.valueOf(logonUser.getOrgId());
			List<Map<String, Object>> amountList4 = dao.queryAreaOem2Cost(areaId, orgId);//总部广告费用
			List<Map<String, Object>> amountList5=dao.queryAreaOemCost(areaId, orgId);//总部市场推广费用
			act.setOutData("areaList", areaList);
			act.setOutData("list", list);
			if(amountList1.size()>0){
				if(amountList1.get(0).get("AVAILABLE_AMOUNT")==null||amountList1.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList1", 0);
				}else{
					act.setOutData("amountList1", amountList1.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList1", 0);
			}
			if(amountList2.size()>0){
				if(amountList2.get(0).get("AVAILABLE_AMOUNT")==null||amountList2.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList2", 0);
				}else{
					act.setOutData("amountList2", amountList2.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList2", 0);
			}
			if(amountList3.size()>0){
				if(amountList3.get(0).get("AVAILABLE_AMOUNT")==null||amountList3.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList3", 0);
				}else{
					act.setOutData("amountList3", amountList3.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList3", 0);
			}
			if(amountList4.size()>0){
				if(amountList4.get(0).get("AVAILABLE_AMOUNT")==null||amountList4.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList4", 0);
				}else{
					act.setOutData("amountList4", amountList4.get(0).get("AVAILABLE_AMOUNT"));
				}
				}
			else{
				act.setOutData("amountList4",0);
			}
			if(amountList5.size()>0){
				if(amountList5.get(0).get("AVAILABLE_AMOUNT")==null||amountList5.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList5", 0);
				}else{
					act.setOutData("amountList5", amountList5.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList5",0);
			}
			//Log ID：<1> 
			//Depiction：<方案编号改为自动生成，需客户提供编码规则> 
			//Writer：PGM 
			//Rewrite Date：<2010-08-24> 
			String campaignNo = SequenceManager.getSequence("CPN");//方案编号
			act.setOutData("campaignNo", campaignNo);
			act.setForword(addUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动方案提报新增页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	
	public void changePrice(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		String areaId=request.getParamValue("areaId");
		String dealerIds=logonUser.getDealerId();
		List<Map<String, Object>> amountList1 = dao.queryDealerCost(dealerIds,areaId);
		List<Map<String, Object>> amountList2 = dao.queryAreaCost(dealerIds,areaId);
		List<Map<String, Object>> amountList3 = dao.queryOemCost();
		
		String orgId=String.valueOf(logonUser.getOrgId());
		List<Map<String, Object>> amountList4 = dao.queryAreaOem2Cost(areaId, orgId);//总部广告费用
		List<Map<String, Object>> amountList5=dao.queryAreaOemCost(areaId, orgId);//总部市场推广费用
		if(amountList2.size()>0){
			if(amountList2.get(0).get("AVAILABLE_AMOUNT")==null||amountList2.get(0).get("AVAILABLE_AMOUNT")==""){
				act.setOutData("price2", 0);
			}else{
				act.setOutData("price2", amountList2.get(0).get("AVAILABLE_AMOUNT"));
			}
		}else{
			act.setOutData("price2", 0);
		}
		if(amountList3.size()>0){
			if(amountList3.get(0).get("AVAILABLE_AMOUNT")==null||amountList3.get(0).get("AVAILABLE_AMOUNT")==""){
				act.setOutData("price3", 0);
			}else{
				act.setOutData("price3", amountList3.get(0).get("AVAILABLE_AMOUNT"));
			}
		}else{
			act.setOutData("price3", 0);
		}
		if(amountList4.size()>0){
			if(amountList4.get(0).get("AVAILABLE_AMOUNT")==null||amountList4.get(0).get("AVAILABLE_AMOUNT")==""){
				act.setOutData("price4", 0);
			}else{
				act.setOutData("price4", amountList4.get(0).get("AVAILABLE_AMOUNT"));
			}
			}
		else{
			act.setOutData("price4",0);
		}
		if(amountList5.size()>0){
			if(amountList5.get(0).get("AVAILABLE_AMOUNT")==null||amountList5.get(0).get("AVAILABLE_AMOUNT")==""){
				act.setOutData("price5", 0);
			}else{
				act.setOutData("price5", amountList5.get(0).get("AVAILABLE_AMOUNT"));
			}
		}else{
			act.setOutData("price5",0);
		}
		if(amountList1.size()>0){
			if(amountList1.get(0).get("AVAILABLE_AMOUNT")==null||amountList1.get(0).get("AVAILABLE_AMOUNT")==""){
				act.setOutData("changePrice", 0);
			}else{
				act.setOutData("changePrice", amountList1.get(0).get("AVAILABLE_AMOUNT"));
			}
		}else{
			act.setOutData("changePrice", 0);
		}
	}

	/**
	 * 活动执行方案提报新增保存
	 */
	public void activitiesPlanReportSave(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String areaId=CommonUtils.checkNull(request.getParamValue("area_id"));
			String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId")) ;					//经销商ID
			String groupId = CommonUtils.checkNull(request.getParamValue("groupId"));						//品牌ID
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));				    //方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));			    //方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));			    //活动主要内容
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));		    //交车数
			String isFleet = CommonUtils.checkNull(request.getParamValue("isFleet"));		    			//是否大客户审核
			
			String costType = CommonUtils.checkNull(request.getParamValue("costType"));			    		//费用类型
			
			String []fjids = request.getParamValues("fjids");					    						//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");									//时间格式化
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);
			
			boolean flag = true;
			String str = "";
		
			if(flag){
				TtCampaignPO ttcp = new TtCampaignPO();									//市场活动方案表
				TtCampaignExecutePO ttcep = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
				//TtCampaignAttachPO ttcap = new TtCampaignAttachPO();					//市场活动附件表
				ttcp.setAreaId(Long.parseLong(areaId));
				String campaignId = SequenceManager.getSequence("");
				ttcp.setCampaignId(Long.parseLong(campaignId));
				ttcp.setGroupId(Long.parseLong(groupId));
				//ttcp.setCampaignModel(Long.parseLong(modelId));
				ttcp.setCampaignNo(campaignNo.trim());
				ttcp.setOemCompanyId(companyId);
				ttcp.setCampaignName(campaignName.trim());
				ttcp.setStartDate(fmat.parse(startDate));
				ttcp.setEndDate(fmat.parse(endDate));
				ttcp.setCampaignSubject(campaignSubject.trim());
				if (null != campaignObject && !"".equals(campaignObject)) {
					ttcp.setCampaignObject(campaignObject.trim());
				}
				if (null != campaignPurpose && !"".equals(campaignPurpose)) {
					ttcp.setCampaignPurpose(campaignPurpose.trim());
				}
				if (null != campaignNeed && !"".equals(campaignNeed)) {
					ttcp.setCampaignNeed(campaignNeed.trim());
				}
				if (null != campaignDesc && !"".equals(campaignDesc)) {
					ttcp.setCampaignDesc(campaignDesc.trim());
				}
				
				ttcp.setCampaignType(Constant.CAMPAIGN_TYPE_02);
				ttcp.setCreateDate(new Date(System.currentTimeMillis()));
				ttcp.setCreateBy(logonUser.getUserId());
				dao.insert(ttcp);				//插入活动方案表	
				TtCampaignGroupRPO tgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				//插入关系表
				String[] modelIds = modelId.split(",");
				if(modelIds != null && modelIds.length > 0){
					for(int i=0;i < modelIds.length;i++){
						String rid = SequenceManager.getSequence("");
						tgr.setRelationId(new Long(rid));
						tgr.setCampaignId(new Long(campaignId));
						tgr.setCampaignModel(new Long(modelIds[i]));
						tgr.setOemCompanyId(companyId);
						tgr.setCreateDate(new Date(System.currentTimeMillis()));
						tgr.setCreateBy(logonUser.getUserId());
						dao.insert(tgr);
					}
				}
				String executeId = SequenceManager.getSequence("");
				Long orgId = DealerInfoDao.getInstance().getOrgId(dealerId) ;
				ttcep.setIsFleet(Long.parseLong(isFleet)) ;
				ttcep.setOrgId(orgId) ;
				ttcep.setExecuteId(Long.parseLong(executeId));
				ttcep.setCampaignId(Long.parseLong(campaignId));
				ttcep.setDealerId(Long.parseLong(dealerId));
				if (null != execAddDesc && !"".equals(execAddDesc)) {
					ttcep.setExecAddDesc(execAddDesc);
				}
				
				ttcep.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_01);
				ttcep.setCreateDate(new Date(System.currentTimeMillis()));
				ttcep.setCreateBy(logonUser.getUserId());
				dao.insert(ttcep);				//插入方案执行表
				String targetId = SequenceManager.getSequence("");
				ttctp.setTargetId(Long.parseLong(targetId));
				ttctp.setExecuteId(Long.parseLong(executeId));
				if (null != callsHousesCntTgt && !"".equals(callsHousesCntTgt)) {
					ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt));
				}
				if (null != reserveCntTgt && !"".equals(reserveCntTgt)) {
					ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt));
				}
				if (null != orderCntTgt && !"".equals(orderCntTgt)) {
					ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt));
				}
				if (null != deliveryCntTgt && !"".equals(deliveryCntTgt)) {
					ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt));
				}
				
				ttctp.setCreateDate(new Date(System.currentTimeMillis()));
				ttctp.setCreateBy(logonUser.getUserId());
				dao.insert(ttctp);				//插入活动目标表
				
				ActivitiesSpacePlanReport asp = new ActivitiesSpacePlanReport() ;
				asp.insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
				asp.insertMediaCost(executeId, fmat, costType, null) ;
				
				//附件添加
				FileUploadManager.fileUploadByBusiness(campaignId, fjids, logonUser);
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
				act.setOutData("returnStr", str);
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动方案提报新增保存");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案提报提交
	 */
	public void activitiesPlanReportConfirm(){
		
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String areaId=request.getParamValue("area_id");//业务范围ID
			String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));						//经销商ID
			String groupId = CommonUtils.checkNull(request.getParamValue("groupId"));						//品牌ID
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));					//方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));				//方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));				//活动主要内容
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));			//交车数
			String isFleet = CommonUtils.checkNull(request.getParamValue("isFleet"));						//是否大客户审核
			
			String costType = CommonUtils.checkNull(request.getParamValue("costType"));			    		//费用类型
			
			String []fjids = request.getParamValues("fjids");												//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");									//时间格式化
			
			Long companyId=GetOemcompanyId.getOemCompanyId(logonUser);
			
			boolean flag = true;
			String str = "";
			
			ActivitiesCostOpera aco = new ActivitiesCostOpera() ;						//---
			aco.activeExecOpera(areaId, costType, "0", Constant.CAMPAIGN_TYPE_02.toString()) ;					
			
			if(flag){
				TtCampaignPO ttcp = new TtCampaignPO();									//市场活动方案表
				TtCampaignExecutePO ttcep = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
				
				ttcp.setAreaId (Long.parseLong(areaId));
				String campaignId = SequenceManager.getSequence("");
				ttcp.setGroupId(Long.parseLong(groupId));
				ttcp.setCampaignId(Long.parseLong(campaignId));
	//			ttcp.setCampaignModel(Long.parseLong(modelId));
				ttcp.setCampaignNo(campaignNo.trim());
				ttcp.setCampaignName(campaignName.trim());
				ttcp.setStartDate(fmat.parse(startDate));
				ttcp.setEndDate(fmat.parse(endDate));
				if (null != campaignSubject && !"".equals(campaignSubject)) {
					ttcp.setCampaignSubject(campaignSubject.trim());
				}
				if (null != campaignObject && !"".equals(campaignObject)) {
					ttcp.setCampaignObject(campaignObject.trim());
				}
				if (null != campaignPurpose && !"".equals(campaignPurpose)) {
					ttcp.setCampaignPurpose(campaignPurpose.trim());
				}
				if (null != campaignNeed && !"".equals(campaignNeed)) {
					ttcp.setCampaignNeed(campaignNeed.trim());
				}
				if (null != campaignDesc && !"".equals(campaignDesc)) {
					ttcp.setCampaignDesc(campaignDesc.trim());
				}
				
				ttcp.setCampaignType(Constant.CAMPAIGN_TYPE_02);
				ttcp.setCreateDate(new Date(System.currentTimeMillis()));
				ttcp.setCreateBy(logonUser.getUserId());
				dao.insert(ttcp);				//插入活动方案表	
				
				TtCampaignGroupRPO tgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				//插入关系表
				String[] modelIds = modelId.split(",");
				if(modelIds != null && modelIds.length > 0){
					for(int i=0;i < modelIds.length;i++){
						String rid = SequenceManager.getSequence("");
						tgr.setRelationId(new Long(rid));
						tgr.setCampaignId(new Long(campaignId));
						tgr.setCampaignModel(new Long(modelIds[i]));
						tgr.setOemCompanyId(companyId);
						tgr.setCreateDate(new Date(System.currentTimeMillis()));
						tgr.setCreateBy(logonUser.getUserId());
						dao.insert(tgr);
					}
				}			
				
				String executeId = SequenceManager.getSequence("");
				Long orgId = DealerInfoDao.getInstance().getOrgId(dealerId) ;
				
				ttcep.setIsFleet(Long.parseLong(isFleet)) ;
				ttcep.setOrgId(orgId) ;
				ttcep.setExecuteId(Long.parseLong(executeId));
				ttcep.setCampaignId(Long.parseLong(campaignId));
				ttcep.setDealerId(Long.parseLong(dealerId));
				if (null != execAddDesc && !"".equals(execAddDesc)) {
					ttcep.setExecAddDesc(execAddDesc.trim());
				}
				
				ttcep.setSubmitsDate(new Date(System.currentTimeMillis())) ;
				ttcep.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_03);
				ttcep.setCreateDate(new Date(System.currentTimeMillis()));
				ttcep.setCreateBy(logonUser.getUserId());
				dao.insert(ttcep);				//插入方案执行表
				String targetId = SequenceManager.getSequence("");
				ttctp.setTargetId(Long.parseLong(targetId));
				ttctp.setExecuteId(Long.parseLong(executeId));
				if (null != callsHousesCntTgt && !"".equals(callsHousesCntTgt)) {
					ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt.trim()));
				}
				if (null != reserveCntTgt && !"".equals(reserveCntTgt)) {
					ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt.trim()));
				}
				if (null != orderCntTgt && !"".equals(orderCntTgt)) {
					ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt.trim()));
				}
				if (null != deliveryCntTgt && !"".equals(deliveryCntTgt)) {
					ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt.trim()));
				}
				
				ttctp.setCreateDate(new Date(System.currentTimeMillis()));
				ttctp.setCreateBy(logonUser.getUserId());
				dao.insert(ttctp);				//插入活动目标表

				ActivitiesSpacePlanReport asp = new ActivitiesSpacePlanReport() ;
				asp.insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
				asp.insertMediaCost(executeId, fmat, costType, null) ;
				
				//附件添加
				FileUploadManager.fileUploadByBusiness(executeId, fjids, logonUser);
				
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
				act.setOutData("returnStr", str);
			}
		} catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动方案提报提交");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案提报明细页面
	 */
	public void activitiesPlanReportDetail(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		List<Map<String, Object>> areaList = MaterialGroupManagerDao.getPoseIdBusiness(logonUser.getPoseId().toString());
		act.setOutData("areaList", areaList);
		try {
			String campaignId = request.getParamValue("campaignId");
			String dealerId = request.getParamValue("dealerId");
			TtCampaignPO mypo1=new TtCampaignPO();
			mypo1.setCampaignId(Long.parseLong(campaignId));
			TtCampaignPO mypo2=new TtCampaignPO();
			mypo2=(TtCampaignPO) dao.select(mypo1).get(0);
			StringBuffer group_id = new StringBuffer();
			StringBuffer group_code = new StringBuffer();
			List<Map<String,String>> actList = dao.queryActiveVehicleType__(campaignId);
			if (null != actList && actList.size()>0) {
				for (int i = 0; i < actList.size(); i++) {
					group_id.append(String.valueOf(actList.get(i).get("GROUP_ID"))).append(",");
					group_code.append(String.valueOf(actList.get(i).get("GROUP_CODE"))).append(",");
				}
			}
			group_id.deleteCharAt(group_id.length()-1);
			group_code.deleteCharAt(group_code.length()-1);
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
			List<Map<String, Object>> list = dao.selectPinPai(oemCompanyId);
			Map<String, Object> map2 = dao.activitiesInfoQuery(campaignId,dealerId);
			String executeId = map2.get("EXECUTE_ID").toString();
			String modelName = dao.getModelName(campaignId);
			Map<String, Object> map3 = dao.activitiesTargetQuery(executeId);
			String areaId=String.valueOf(mypo2.getAreaId());
			String orgId=String.valueOf(logonUser.getOrgId());
			List<Map<String, Object>> list1 = dao.getActivitiesCostbyId(executeId, campaignId);
			List<Map<String, Object>> list2 = SpacePlanReportDao.getActivitiesMediaCost(executeId);
			List<Map<String, Object>> list3 = dao.getCheckInfo(executeId);
			List<Map<String, Object>> amountList1 = dao.queryDealerCost(dealerId,areaId);//经销商费用
			List<Map<String, Object>> amountList2 = dao.queryAreaCost(dealerId,areaId);//区域费用
			List<Map<String, Object>> amountList3 = dao.queryOemCost();
			List<Map<String, Object>> amountList4 = dao.queryAreaOem2Cost(areaId, orgId);//总部广告费用
			List<Map<String, Object>> amountList5=dao.queryAreaOemCost(areaId, orgId);//总部市场推广费用
			if(amountList4.size()>0){
				if(amountList4.get(0).get("AVAILABLE_AMOUNT")==null||amountList4.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList4", 0);
				}else{
					act.setOutData("amountList4", amountList4.get(0).get("AVAILABLE_AMOUNT"));
				}
				}
			else{
				act.setOutData("amountList4",0);
			}
			if(amountList5.size()>0){
				if(amountList5.get(0).get("AVAILABLE_AMOUNT")==null||amountList5.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList5", 0);
				}else{
					act.setOutData("amountList5", amountList5.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList5",0);
			}
			
			act.setOutData("areaId", areaId) ;
			act.setOutData("group_id", group_id.toString());
			act.setOutData("group_code", group_code.toString());
			act.setOutData("map2", map2);
			act.setOutData("map3", map3);
			act.setOutData("list", list);
			
			String type = "" ;
			if(list1.size()>0&&list1.get(0).get("ITEM_COUNT")!=null){
				type = list1.get(0).get("COST_TYPE").toString() ;
				
				act.setOutData("list1", list1);
			}
			if(list2.size()>0&&list2.get(0).get("ITEM_COUNT")!=null){
				type = list2.get(0).get("COST_TYPE").toString() ;
				
				act.setOutData("list2", list2);
			}
			act.setOutData("type", type) ;
			
			act.setOutData("list3", list3);
			act.setOutData("modelName",modelName);
			if(amountList1.size()>0){
				if(amountList1.get(0).get("AVAILABLE_AMOUNT")==null||amountList1.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList1", 0);
				}else{
					act.setOutData("amountList1", amountList1.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList1", 0);
			}
			if(amountList2.size()>0){
				if(amountList2.get(0).get("AVAILABLE_AMOUNT")==null||amountList2.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList2", 0);
				}else{
					act.setOutData("amountList2", amountList2.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList2", 0);
			}
			if(amountList3.size()>0){
				if(amountList3.get(0).get("AVAILABLE_AMOUNT")==null||amountList3.get(0).get("AVAILABLE_AMOUNT")==""){
					act.setOutData("amountList3", 0);
				}else{
					act.setOutData("amountList3", amountList3.get(0).get("AVAILABLE_AMOUNT"));
				}
			}else{
				act.setOutData("amountList3", 0);
			}
			//根据campaignId查询上传附件
			List<Map<String, Object>> attachList = dao.getAttachInfos(campaignId);
			if(null!=attachList&&attachList.size()!=0){
				act.setOutData("attachList", attachList);
			}
			act.setOutData("myDate",Constant.CAMPAIGN_TYPE_01);
			act.setOutData("dealerId", dealerId);
			act.setForword(detailUrl);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"活动执行方案提报明细页面");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 活动执行方案提报明细页面保存
	 */
	public void activitiesPlanDetailSave(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String campaignId = CommonUtils.checkNull(request.getParamValue("campaignId"));					//方案ID
			String executeId = CommonUtils.checkNull(request.getParamValue("executeId"));					//执行ID
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));					//方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));				//方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));				//活动主要内容
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));			//交车数
			String isFleet = CommonUtils.checkNull(request.getParamValue("isFleet"));						//是否大客户审核
			
			String costType = CommonUtils.checkNull(request.getParamValue("costType"));			    		//费用类型
			
			String []fjids = request.getParamValues("fjids");							//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");			//时间格式化
			
			
			boolean flag = true;
			String str = "";
			
			if(flag){
				TtCampaignPO ttcp1 = new TtCampaignPO();								//市场活动方案表
				TtCampaignPO ttcp2 = new TtCampaignPO();								//市场活动方案表
				TtCampaignExecutePO ttcep1 = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignExecutePO ttcep2 = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
				TtCamCampaignCostPO ttccp = new TtCamCampaignCostPO();					//市场活动费用表
				TtCamMediaCostPO tcmcp	= new TtCamMediaCostPO();						//媒体投放费用表
				ttcp1.setCampaignId(Long.parseLong(campaignId));
				
				if (null != campaignNo && !"".equals(campaignNo)) {
					ttcp2.setCampaignNo(campaignNo.trim());
				}
				if (null != campaignName && !"".equals(campaignName)) {
					ttcp2.setCampaignName(campaignName.trim());
				}
				ttcp2.setStartDate(fmat.parse(startDate));
				ttcp2.setEndDate(fmat.parse(endDate));
				if (null != campaignSubject && !"".equals(campaignSubject)) {
					ttcp2.setCampaignSubject(campaignSubject.trim());
				}
				if (null != campaignObject && !"".equals(campaignObject)) {
					ttcp2.setCampaignObject(campaignObject.trim());
				}
				if (null != campaignPurpose && !"".equals(campaignPurpose)) {
					ttcp2.setCampaignPurpose(campaignPurpose.trim());
				}
				if (null != campaignNeed && !"".equals(campaignNeed)) {
					ttcp2.setCampaignNeed(campaignNeed.trim());
				}
				if (null != campaignDesc && !"".equals(campaignDesc)) {
					ttcp2.setCampaignDesc(campaignDesc.trim());
				}
				
				ttcp2.setUpdateDate(new Date(System.currentTimeMillis()));
				ttcp2.setUpdateBy(logonUser.getUserId());
				dao.update(ttcp1,ttcp2);				//更新活动方案表	
				
				Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
				TtCampaignGroupRPO dtgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				dtgr.setCampaignId(new Long(campaignId));
				dtgr.setOemCompanyId(oemCompanyId);
				dao.delete(dtgr);
				
				TtCampaignGroupRPO tgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				//新增插入关系表
				String[] modelIds = {};
				if (null != modelId && !"".equals(modelId)) {
					modelIds = modelId.split(",");
				}
				if(modelIds != null && modelIds.length > 0){
					for(int i=0;i < modelIds.length;i++){
						String rid = SequenceManager.getSequence("");
						tgr.setRelationId(new Long(rid));
						tgr.setCampaignId(new Long(campaignId));
						tgr.setCampaignModel(new Long(modelIds[i]));
						tgr.setOemCompanyId(oemCompanyId);
						tgr.setCreateDate(new Date(System.currentTimeMillis()));
						tgr.setCreateBy(logonUser.getUserId());
						dao.insert(tgr);
					}
				}
				
				ttcep1.setExecuteId(Long.parseLong(executeId));
				Long orgId = DealerInfoDao.getInstance().getOrgId(logonUser.getDealerId()) ;
				
				ttcep2.setIsFleet(Long.parseLong(isFleet)) ;
				ttcep2.setOrgId(orgId) ;
				ttcep2.setExecAddDesc(execAddDesc);
				ttcep2.setUpdateDate(new Date(System.currentTimeMillis()));
				ttcep2.setUpdateBy(logonUser.getUserId());
				dao.update(ttcep1,ttcep2);				//更新方案执行表
				
				ttctp.setExecuteId(Long.parseLong(executeId));
				dao.delete(ttctp);						//删除活动目标
				String targetId = SequenceManager.getSequence("");
				ttctp.setTargetId(Long.parseLong(targetId));
				ttctp.setExecuteId(Long.parseLong(executeId));
				if (null != callsHousesCntTgt && !"".equals(callsHousesCntTgt)) {
					ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt));
				}
				if (null != reserveCntTgt && !"".equals(reserveCntTgt)) {
					ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt));
				}
				if (null != orderCntTgt && !"".equals(orderCntTgt)) {
					ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt));
				}
				if (null != deliveryCntTgt && !"".equals(deliveryCntTgt)) {
					ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt));
				}
				
				ttctp.setCreateDate(new Date(System.currentTimeMillis()));
				ttctp.setCreateBy(logonUser.getUserId());
				dao.insert(ttctp);				//插入活动目标表
				ttccp.setExecuteId(Long.parseLong(executeId));
				dao.delete(ttccp);				//删除活动费用表

				tcmcp.setExecuteId(Long.parseLong(executeId));
				dao.delete(tcmcp);				//删除媒体投放费用表
				
				ActivitiesSpacePlanReport asp = new ActivitiesSpacePlanReport() ;
				asp.insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
				asp.insertMediaCost(executeId, fmat, costType, null) ;
				
				//附件添加
				FileUploadManager.fileUploadByBusiness(campaignId, fjids, logonUser);
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
				act.setOutData("returnStr", str);
			}
			
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动执行方案提报明细保存");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案提报明提报
	 */
	public void activitiesPlanDetailConfirm(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String areaId=CommonUtils.checkNull(request.getParamValue("area_id"));
			String campaignId = CommonUtils.checkNull(request.getParamValue("campaignId"));					//方案ID
			String executeId = CommonUtils.checkNull(request.getParamValue("executeId"));					//执行ID
			String modelId = CommonUtils.checkNull(request.getParamValue("modelId"));						//活动车型ID
			String campaignNo = CommonUtils.checkNull(request.getParamValue("campaignNo"));					//方案编号
			String campaignName = CommonUtils.checkNull(request.getParamValue("campaignName"));				//方案名称
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));					//开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));						//结束时间
			String campaignSubject = CommonUtils.checkNull(request.getParamValue("campaignSubject"));		//活动主题
			String campaignObject = CommonUtils.checkNull(request.getParamValue("campaignObject"));			//活动对象
			String campaignPurpose = CommonUtils.checkNull(request.getParamValue("campaignPurpose"));		//活动目的
			String campaignNeed = CommonUtils.checkNull(request.getParamValue("campaignNeed"));				//活动要求
			String campaignDesc = CommonUtils.checkNull(request.getParamValue("campaignDesc"));				//活动主要内容
			String execAddDesc = CommonUtils.checkNull(request.getParamValue("execAddDesc"));				//活动地点说明
			String callsHousesCntTgt = CommonUtils.checkNull(request.getParamValue("callsHousesCntTgt"));	//来电来店数
			String reserveCntTgt = CommonUtils.checkNull(request.getParamValue("reserveCntTgt"));			//信息留存数
			String orderCntTgt = CommonUtils.checkNull(request.getParamValue("orderCntTgt"));				//订单数
			String deliveryCntTgt = CommonUtils.checkNull(request.getParamValue("deliveryCntTgt"));			//交车数
			String isFleet = CommonUtils.checkNull(request.getParamValue("isFleet"));						//是否大客户审核
			
			String costType = CommonUtils.checkNull(request.getParamValue("costType"));			    		//费用类型
			
			String []fjids = request.getParamValues("fjids");							//附件ID
			SimpleDateFormat fmat = new SimpleDateFormat ("yyyy-MM-dd");			//时间格式化
			
			boolean flag = true;
			String str = "";
			
			ActivitiesCostOpera aco = new ActivitiesCostOpera() ;
			aco.activeExecOpera(areaId, costType, "0", Constant.CAMPAIGN_TYPE_02.toString()) ;				
			
			if(flag){
				TtCampaignPO ttcp1 = new TtCampaignPO();								//市场活动方案表
				TtCampaignPO ttcp2 = new TtCampaignPO();								//市场活动方案表
				TtCampaignExecutePO ttcep1 = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignExecutePO ttcep2 = new TtCampaignExecutePO();					//活动方案执行表
				TtCampaignTargetPO ttctp = new TtCampaignTargetPO();					//市场活动目标表
				TtCamCampaignCostPO ttccp = new TtCamCampaignCostPO();					//市场活动费用表
				TtCamMediaCostPO tcmcp	= new TtCamMediaCostPO();						//媒体投放费用表
				ttcp1.setCampaignId(Long.parseLong(campaignId));
	//			ttcp2.setCampaignModel(Long.parseLong(modelId));
				ttcp2.setCampaignNo(campaignNo.trim());
				ttcp2.setCampaignName(campaignName.trim());
				ttcp2.setStartDate(fmat.parse(startDate));
				ttcp2.setEndDate(fmat.parse(endDate));
				ttcp2.setAreaId(Long.parseLong(areaId));
				if (null != campaignSubject && !"".equals(campaignSubject)) {
					ttcp2.setCampaignSubject(campaignSubject.trim());
				}
				if (null != campaignObject && !"".equals(campaignObject)) {
					ttcp2.setCampaignObject(campaignObject.trim());
				}
				if (null != campaignPurpose && !"".equals(campaignPurpose)) {
					ttcp2.setCampaignPurpose(campaignPurpose.trim());
				}
				if (null != campaignNeed && !"".equals(campaignNeed)) {
					ttcp2.setCampaignNeed(campaignNeed.trim());
				}
				if (null != campaignDesc && !"".equals(campaignDesc)) {
					ttcp2.setCampaignDesc(campaignDesc.trim());
				}
				if(!"".equals(request.getParamValue("adviceDesc")) && request.getParamValue("adviceDesc") != null){
					ttcep2.setAdviceDesc(request.getParamValue("adviceDesc"));
				}
				
				ttcp2.setUpdateDate(new Date(System.currentTimeMillis()));
				ttcp2.setCreateBy(logonUser.getUserId()) ;
				ttcp2.setUpdateBy(logonUser.getUserId());
				dao.update(ttcp1,ttcp2);				//更新活动方案表
				
				Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
				TtCampaignGroupRPO dtgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				dtgr.setCampaignId(new Long(campaignId));
				dtgr.setOemCompanyId(oemCompanyId);
				dao.delete(dtgr);
				
				TtCampaignGroupRPO tgr = new TtCampaignGroupRPO(); //市场活动和车型明细关系表
				//新增插入关系表
				String[] modelIds = {};
				if (null != modelId && !"".equals(modelId)) {
					modelIds = modelId.split(",");
				}
				if(modelIds != null && modelIds.length > 0){
					for(int i=0;i < modelIds.length;i++){
						String rid = SequenceManager.getSequence("");
						tgr.setRelationId(new Long(rid));
						tgr.setCampaignId(new Long(campaignId));
						tgr.setCampaignModel(new Long(modelIds[i]));
						tgr.setOemCompanyId(oemCompanyId);
						tgr.setCreateDate(new Date(System.currentTimeMillis()));
						tgr.setCreateBy(logonUser.getUserId());
						dao.insert(tgr);
					}
				}
				
				ttcep1.setExecuteId(Long.parseLong(executeId));
				if (null != execAddDesc && !"".equals(execAddDesc)) {
					ttcep2.setExecAddDesc(execAddDesc.trim());
				}
				
				Long orgId = DealerInfoDao.getInstance().getOrgId(logonUser.getDealerId()) ;
				ttcep2.setIsFleet(Long.parseLong(isFleet)) ;
				ttcep2.setOrgId(orgId) ;
				ttcep2.setSubmitsDate(new Date(System.currentTimeMillis())) ;
				ttcep2.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_03);
				ttcep2.setUpdateDate(new Date(System.currentTimeMillis()));
				ttcep2.setUpdateBy(logonUser.getUserId());
				dao.update(ttcep1,ttcep2);				//更新方案执行表
				
				ttctp.setExecuteId(Long.parseLong(executeId));
				dao.delete(ttctp);						//删除活动目标
				String targetId = SequenceManager.getSequence("");
				ttctp.setTargetId(Long.parseLong(targetId));
				ttctp.setExecuteId(Long.parseLong(executeId));
				if (null != callsHousesCntTgt && !"".equals(callsHousesCntTgt)) {
					ttctp.setCallsHousesCntTgt(Integer.parseInt(callsHousesCntTgt));
				}
				if (null != reserveCntTgt && !"".equals(reserveCntTgt)) {
					ttctp.setReserveCntTgt(Integer.parseInt(reserveCntTgt));
				}
				if (null != orderCntTgt && !"".equals(orderCntTgt)) {
					ttctp.setOrderCntTgt(Integer.parseInt(orderCntTgt));
				}
				if (null != deliveryCntTgt && !"".equals(deliveryCntTgt)) {
					ttctp.setDeliveryCntTgt(Integer.parseInt(deliveryCntTgt));
				}
				
				ttctp.setCreateDate(new Date(System.currentTimeMillis()));
				ttctp.setCreateBy(logonUser.getUserId());
				dao.insert(ttctp);				//插入活动目标表
				
				ttccp.setExecuteId(Long.parseLong(executeId));
				dao.delete(ttccp);				//删除活动费用表
				
				tcmcp.setExecuteId(Long.parseLong(executeId));
				dao.delete(tcmcp);				//删除媒体投放费用表
				
				ActivitiesSpacePlanReport asp = new ActivitiesSpacePlanReport() ;
				asp.insertCampaignCost(costType, campaignId, executeId, fmat, null) ;
				asp.insertMediaCost(executeId, fmat, costType, null) ;
				
				//附件添加
				FileUploadManager.fileUploadByBusiness(campaignId, fjids, logonUser);
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
				act.setOutData("returnStr", str);
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.PUTIN_FAILURE_CODE,"活动执行方案提报明细提报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**
	 * 活动执行方案取消
	 */
	public void activitiesPlanCencle(){
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String executeId = request.getParamValue("executeId");					//执行ID
			TtCampaignExecutePO ttcep1 = new TtCampaignExecutePO();					//活动方案执行表
			TtCampaignExecutePO ttcep2 = new TtCampaignExecutePO();					//活动方案执行表
			ttcep1.setExecuteId(Long.parseLong(executeId));
			ttcep2.setCheckStatus(Constant.CAMPAIGN_CHECK_STATUS_11);
			ttcep2.setUpdateDate(new Date(System.currentTimeMillis()));
			ttcep2.setUpdateBy(logonUser.getUserId());
			dao.update(ttcep1,ttcep2);				//更新方案执行表
			act.setOutData("returnValue", 1);
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SAVE_FAILURE_CODE,"活动执行方案提报明细提报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void notifySession() {
		String func = CommonUtils.checkNull(request.getParamValue("func")) ;
		
		System.out.println("NOTIFY_SESSION_FUNCTION: " + func) ;
	}
}


